import { Controller, Get, Put, Delete, Param, Body, Query, Post, Patch } from '@nestjs/common';
import { SensitiveWordService } from './sensitive-word.service';
import { Comment } from '../../entities/comment.entity';
import { Admin } from '../../common/decorators/admin.decorator';
import { ApiTags, ApiOperation, ApiResponse, ApiBody, ApiParam, ApiQuery } from '@nestjs/swagger';

@ApiTags('评论管理（管理员）')
@Controller('api/admin/sensitive')
export class SensitiveAdminController {
  constructor(
    private readonly sensitiveWordService: SensitiveWordService,
  ) {}

  // ==================== 敏感词管理 ====================
  // 获取所有敏感词
  @Admin()
  @Get('sensitive-words')
  @ApiOperation({
    summary: '获取所有敏感词',
    description: '管理员获取系统中的所有敏感词',
  })
  @ApiResponse({
    status: 200,
    description: '获取成功',
  })
  getAllSensitiveWords() {
    console.log('Getting all sensitive words...');
    return this.sensitiveWordService.findAllAdmin();
  }

  // 添加敏感词
  @Admin()
  @Post('sensitive-words')
  @ApiOperation({
    summary: '添加敏感词',
    description: '管理员添加新的敏感词',
  })
  @ApiBody({
    schema: {
      example: {
        word: '垃圾',
      },
    },
  })
  @ApiResponse({
    status: 201,
    description: '添加成功',
  })
  @ApiResponse({
    status: 400,
    description: '敏感词已存在',
  })
  createSensitiveWord(@Body('word') word: string) {
    return this.sensitiveWordService.create(word);
  }

  // 批量添加敏感词
  @Admin()
  @Post('sensitive-words/batch')
  @ApiOperation({
    summary: '批量添加敏感词',
    description: '管理员批量添加敏感词',
  })
  @ApiBody({
    schema: {
      example: {
        words: ['垃圾', '广告', 'spam'],
      },
    },
  })
  @ApiResponse({
    status: 201,
    description: '批量添加成功',
  })
  createSensitiveWordsBatch(@Body('words') words: string[]) {
    return this.sensitiveWordService.createBatch(words);
  }

  // 更新敏感词
  @Admin()
  @Patch('sensitive-words/:id')
  @ApiOperation({
    summary: '更新敏感词',
    description: '管理员更新指定敏感词',
  })
  @ApiParam({
    name: 'id',
    description: '敏感词ID',
    example: '1',
  })
  @ApiBody({
    schema: {
      example: {
        word: '新敏感词',
      },
    },
  })
  @ApiResponse({
    status: 200,
    description: '更新成功',
  })
  updateSensitiveWord(@Param('id') id: number, @Body('word') word: string) {
    return this.sensitiveWordService.update(id, word);
  }

  // 更新敏感词状态
  @Admin()
  @Patch('sensitive-words/:id/status')
  @ApiOperation({
    summary: '更新敏感词状态',
    description: '管理员启用/禁用敏感词',
  })
  @ApiParam({
    name: 'id',
    description: '敏感词ID',
    example: '1',
  })
  @ApiBody({
    schema: {
      example: {
        isActive: 1, // 0禁用，1启用
      },
    },
  })
  @ApiResponse({
    status: 200,
    description: '更新成功',
  })
  updateSensitiveWordStatus(@Param('id') id: number, @Body('isActive') isActive: number) {
    return this.sensitiveWordService.updateStatus(id, isActive);
  }

  // 删除敏感词
  @Admin()
  @Delete('sensitive-words/:id')
  @ApiOperation({
    summary: '删除敏感词',
    description: '管理员删除指定敏感词',
  })
  @ApiParam({
    name: 'id',
    description: '敏感词ID',
    example: '1',
  })
  @ApiResponse({
    status: 200,
    description: '删除成功',
  })
  deleteSensitiveWord(@Param('id') id: number) {
    return this.sensitiveWordService.remove(id);
  }

  // 批量删除敏感词
  @Admin()
  @Delete('sensitive-words/batch')
  @ApiOperation({
    summary: '批量删除敏感词',
    description: '管理员批量删除敏感词',
  })
  @ApiBody({
    schema: {
      example: {
        ids: [1, 2, 3],
      },
    },
  })
  @ApiResponse({
    status: 200,
    description: '批量删除成功',
  })
  deleteSensitiveWordsBatch(@Body('ids') ids: number[]) {
    return this.sensitiveWordService.removeBatch(ids);
  }



  // 获取评论统计数据
  // @Admin()
  // @Get('stats')
  // @ApiOperation({
  //   summary: '获取评论统计',
  //   description: '获取评论相关统计数据',
  // })
  // @ApiResponse({
  //   status: 200,
  //   description: '获取成功',
  // })
  // @ApiResponse({
  //   status: 403,
  //   description: '无管理员权限',
  // })
  // getStats() {
  //   return this.commentService.getStats();
  // }

}